#!/usr/bin/env node

const mysql = require('mysql2/promise'),
      log = console.log;

let con = mysql.createPool({
  host:'localhost',
    user:'root',
    password:'ddd',
    database:'test'

});

async function addArea(areaname){
  const sql = `insert into areas(area_name) values('${areaname}')`;
  let [rows] = await con.execute(sql);
  return rows;
}

async function delArea(areaname){
  const sql = `delete from areas where area_name='${areaname}'`;
  //const sql = `delete from areas where area_name='港澳台';`
  let [rows] = await con.execute(sql);
  return rows;

}

async function updateArea(old_name,new_name){
  const sql = `update areas set area_name = '${new_name}' where area_name='${old_name}'`;
  let [rows] = await con.execute(sql);
  return rows;
}
async function getAreas(){
  const sql = 'select * from areas';
  let [rows] = await con.execute(sql);
  return rows;
}

(async function(){

  //await addArea('UK');
  log(await getAreas());
  //await updateArea('日','港台');
  //log(await getAreas());
  await delArea('mysql> showdatabases');
  log(await getAreas());

})();
